package handler

import (
	"github.com/gin-gonic/gin"
	"net/http"
	"zk3.12/api/request"
	"zk3.12/glodal"
	"zk3.12/internal/model"
)

func LiveRoomAdd(c *gin.Context) {
	var req request.LiveRoomAdd
	err := c.ShouldBind(&req)
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  "验证失败",
			"data": err.Error(),
		})
		return
	}
	room := model.LiveRoom{
		LiveId: req.LiveId,
		UserId: req.UserId,
		Name:   req.Name,
		Sex:    req.Sex,
	}
	err = glodal.DB.Create(&room).Error
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  "进入直播间失败",
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "进入直播间成功",
		"data": room,
	})
}

func LiveRoomList(c *gin.Context) {
	var room []model.LiveRoom
	err := glodal.DB.Find(&room).Error
	if err != nil {
		c.JSON(http.StatusOK, gin.H{
			"code": 0,
			"msg":  "直播间查看是吧",
			"data": nil,
		})
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "直播间查看成功",
		"data": room,
	})
}
